require 'piston/plugin/project/command/drop'
require 'piston/plugin/project/command/search_file'
require 'piston/plugin/project/command/open_project_item'
require 'piston/plugin/project/model/project_item'
require 'piston/plugin/project/view_model/project_item_view_model'
require 'piston/plugin/project/view_model/project_view_model'

module Piston
  class Plugin
    def view(xaml_builder)
      puts xaml_builder
    end

    def after_build(win)
      xaml_file = File.join(File.expand_path(File.dirname(__FILE__)), 'view/project.xaml')
      document = System::Windows::Markup::XamlReader.load_file xaml_file

      document.drop do |sender, e|
        files = e.Data.GetData("FileDrop")
        sender.data_context.file_drop(files)
      end

      document.find_name("menu_open_project_item").click do
        puts "333333333"
        command = Piston::Project::OpenProjectItem.new(document)
        command.execute(document)
      end

      view_model = Piston::Project::ProjectViewModel.new
      document.data_context = view_model
      doc_pane = win.find_name('WinFormsWindow')
      doc_pane.content = document
    end
  end
end